package cn.t.enums.order;


import cn.t.core.enums.Enumer;
import cn.t.core.enums.base.CommonEnum;
import com.baomidou.mybatisplus.annotation.EnumValue;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;

/**
 * @author l
 */
@Enumer
@Getter
@AllArgsConstructor
public enum ReplenishmentStatusEnum implements CommonEnum<Integer,String> {
  //  补货状态 0：待办 1：已结单 2：部分完成 3：关闭
    PENDING(0, "待补货", "待补货"),
    SETTLED(1, "已完成", "已完成"),
    PARTIALLY_COMPLETED(2, "部分完成", "部分完成"),
    CLOSED(3, "关闭", "已取消");
    public static final List<Integer> closedList = Arrays.asList(CLOSED.getCode(),SETTLED.getCode());
    public static final List<Integer> PARTIALLYCOMPLETED = Arrays.asList(PENDING.getCode(),PARTIALLY_COMPLETED.getCode());
    @JsonValue
    @EnumValue
    private final Integer code;
    private final String name;
    private final String alias;
    public static  String getName(Integer key) {
        for (ReplenishmentStatusEnum replenishmentStatusEnum : ReplenishmentStatusEnum.values()) {
            if (replenishmentStatusEnum.getCode().equals(key)) {
                return replenishmentStatusEnum.getName();
            }
        }
        return "";
    }

    public static String getAlias(Integer key) {
        for (ReplenishmentStatusEnum replenishmentStatusEnum : ReplenishmentStatusEnum.values()) {
            if (replenishmentStatusEnum.getCode().equals(key)) {
                return replenishmentStatusEnum.getAlias();
            }
        }
        return "";
    }
    public static ReplenishmentStatusEnum getStatusEnum(Integer actualRsQty, Integer rsQty) {
        if (actualRsQty==null){
            return ReplenishmentStatusEnum.PENDING;
        }
        if (actualRsQty> 0 && actualRsQty < rsQty) {
            return ReplenishmentStatusEnum.PARTIALLY_COMPLETED;
        }else if (actualRsQty > 0) {
            return ReplenishmentStatusEnum.SETTLED;
        }else {
            return ReplenishmentStatusEnum.PENDING;
        }

    }
}
